/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-11-26
 * Time: 23:20
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;

using Labb4.Media.Graphics;

namespace Labb4.Entity
{
	/// <summary>
	/// A graphical entity represented by an image only.
	/// </summary>
	public class PictureEntity : BasicEntity
	{
		#region members
		
		/// <summary>
		/// Reference to the renderer
		/// </summary>
		private RenderManager		m_RenderManager = RenderManager.Instance;
		/// <summary>
		/// The picture of this graphical entity
		/// </summary>
		//private Picture				m_PictureData;
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, calls base, sets the picture
		/// </summary>
		/// <param name="picture">The picture for this picture entity</param>
		/// <param name="x">The x coordinate for this entity</param>
		/// <param name="y">The y coordinate for this entity</param>
		/// <param name="width">This entity's width</param>
		/// <param name="height">This entity's height</param>
		/// <param name="velocity">The starting velocity of this entity</param>
		/// <param name="direction">The initial direction of this entity</param>
		public PictureEntity(Picture picture, float x, float y, int width, int height, float velocity, float direction) :
			base(x, y, width, height, velocity, direction, picture)
		{
			//m_PictureData = picture;
		}
		
		#endregion
		
		#region overrides
		
		/// <summary>
		/// <see cref="Entity#Update">Update in Entity</see>
		/// </summary>
		/// <param name="deltaTime">Time passed since last update. Unit is (ms)</param>
		public override void Update(ref int deltaTime)
		{
			base.Update(ref deltaTime);
		}
		
		/// <summary>
		/// Determines if a point is a color or not. If the color key has not been set, all points
		/// within the entity's range will be concidered color. The given coordinates are relative
		/// to the screen, not the entity.
		/// </summary>
		/// <param name="x">The screen relative x coordinate to check</param>
		/// <param name="y">The screen relative y coordinate to check</param>
		/// <returns></returns>
		public override bool PointIsColor(ref int x, ref int y)
		{
			int relX = x - (int)m_Xpos;
			int relY = y - (int)m_Ypos;
			
			return m_PictureData.PointIsColor(ref relX, ref relY);
			//return m_PictureData.PointIsColor(ref x - (int)m_Xpos, ref y - (int)m_Ypos);
		}
		
		/// <summary>
		/// Draws the entity to the screen
		/// </summary>
		public override void Draw()
		{
			if(m_Active)
			{
				Rectangle dest = new Rectangle((int)m_Xpos, (int)m_Ypos, m_PictureData.ImageData.Width, m_PictureData.ImageData.Height);
				Rectangle source = new Rectangle(0, 0, dest.Width, dest.Height);
				m_RenderManager.DrawPicture(m_PictureData, dest, source);
			}
		}
		
		#endregion
	}
}
